#!/usr/bin/env bash
# ******************************************************
# Filename     : dns_ubuntu_install.sh
# Last modified: 2024-08-23 12:18
# Version      :
# AppVersion   : 32:9.11.36-5.el8
# Author       : jack.zang
# Email        : jack_zang@126.com
# Description  : 部署前，请修改 DOMAIN HOSTIP REVERSE_LOOKUP_ADDR
# source <(curl -sL https://gitee.com/jack_zang/public-scripts/raw/master/shell/dns/dns_ubuntu_install.sh)
# Add DNS Resolution: echo "www A 192.168.10.237" >> /var/named/xiodi.cn.zone && rndc reload
#
# ******************************************************

DOMAIN="xiodi.cn"
HOSTIP="192.168.11.239"
REVERSE_LOOKUP_ADDR="11.168.192"

apt-get -y install bind9


cat > /etc/bind/named.conf.options <<EOF
options {
        directory "/var/cache/bind";
        forwarders {
            8.8.8.8;
            4.4.4.4;
        };
        dnssec-validation auto;
        listen-on { ${HOSTIP}; };
        listen-on-v6 { none; };
};
EOF

cat >> /etc/bind/named.conf.local <<EOF
zone "$DOMAIN" IN {
    type master;
    file "/etc/bind/${DOMAIN}.zone";
    allow-update { none; };
};
EOF

cat > /etc/bind/${DOMAIN}.zone <<EOF
\$TTL 1D
@	    IN   SOA	  dns.${DOMAIN}. root.${DOMAIN}. ( 0 1D 1H 1W 3H )
@     IN   NS     dns.${DOMAIN}.
@     IN   A      ${HOSTIP}
dns        A      ${HOSTIP}
test       A      1.1.1.11
EOF

systemctl enable named && systemctl restart bind9

### 验证
# apt-get install -y dnsutils
# dig test.xiodi.cn
# rndc reload   // 重新加载配置


